package com.lixin.smartclassroom.ui.home.tab1.activity

import android.app.Activity
import android.widget.LinearLayout
import com.drake.net.utils.scopeNetLife
import com.lixin.smartclassroom.api.getclassnews
import com.lixin.smartclassroom.bean.BaseBean
import com.lixin.smartclassroom.bean.DataListBean
import com.lixin.smartclassroom.common.messageUnreadDialog
import com.lixin.smartclassroom.databinding.ActivityMessageDetailBinding
import com.lixin.smartclassroom.ext.user_role
import com.lixin.smartclassroom.ui.home.adapter.imgList
import com.lixin.smartclassroom.ui.home.adapter.studentRead
import com.lixinkeji.base.BaseActivity
import com.lixinkeji.extension.dp2px
import com.lixinkeji.extension.getIntentString
import com.lixinkeji.extension.gone
import com.lixinkeji.extension.loadRound
import com.lixinkeji.extension.onClick
import com.lixinkeji.extension.screenWidth
import com.lixinkeji.extension.visible

/**
 * Description 消息详情
 * Author: lwc
 * Date:2023/12/7 15:49
 */
class MessageDetailAct : BaseActivity<ActivityMessageDetailBinding>() {

    override fun getViewBinding() = ActivityMessageDetailBinding.inflate(layoutInflater)
    override fun topBarHide() = false
    override fun startPadding() = true
    override fun title() = "消息详情"
    private lateinit var listBean: ArrayList<DataListBean>

    private var calssnewsid = ""
    private lateinit var baseBean:BaseBean

    override fun iniView() {
        val imgLayoutParams = LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT
        )
        imgLayoutParams.width = ((screenWidth() - dp2px(80f) + dp2px(24f)) / 9).toInt()
        imgLayoutParams.height = ((screenWidth() - dp2px(80f) + dp2px(24f)) / 9).toInt()
        binding.tvMoreRead.layoutParams = imgLayoutParams
        binding.tvMoreUnread.layoutParams = imgLayoutParams


        calssnewsid = getIntentString("calssnewsid")

        binding.apply {
            scopeNetLife {
                baseBean = getclassnews(calssnewsid)
                if (baseBean.result == "0") {
                    tvTitle.text = baseBean.title
                    tvCrateTime.text = baseBean.createdate
                    tvContent.text = baseBean.content
                    if (baseBean.image.isNullOrEmpty()) {
                        img.gone()
                    } else {
                        if (baseBean.image!!.contains(",")) {
                            img.gone()
                            rcvImage.visible()
                            rcvImage.imgList(2).models = baseBean.image!!.split(",")
                        } else {
                            img.visible()
                            rcvImage.gone()
                            img.loadRound(baseBean.image!!)
                        }

                    }

                    when (user_role) {
                        3 -> {
                            binding.llTeacher.visible()

                            binding.recyclerRead.studentRead().models = baseBean.ydcustomer
                            binding.recyclerUnRead.studentRead().models = baseBean.wdcustomer

                        }
                    }
                }
            }
        }
    }

    override fun onClick() {
        binding.apply {
            tvMoreRead.onClick {
                messageUnreadDialog("已读学生",baseBean.ydcustomer!!)
            }
            tvMoreUnread.onClick {
                messageUnreadDialog("未读学生",baseBean.wdcustomer!!)
            }
        }
    }
}